package com.imooc.o2o.web.superadmin;

import com.imooc.o2o.entity.Area;
import com.imooc.o2o.service.AreaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author 徐老板
 * @date 2019/12/28   20:33
 */
@Controller
@RequestMapping("/superadmin")
public class AreaController {
Logger logger=LoggerFactory.getLogger(AreaController.class);

    @Autowired
    AreaService areaService;

    @GetMapping("/listarea")
    @ResponseBody
    private Map<String,Object> listArea(){
        logger.info("============start============");
        long startTime = System.currentTimeMillis();

        Map<String,Object> modelMap=new HashMap<>();
        List<Area> areaList = new ArrayList<>();

        try {
            areaList = areaService.getAreaList();
            modelMap.put("rows", areaList);
            modelMap.put("total",areaList.size() );
        } catch (Exception e) {
            e.printStackTrace();
            modelMap.put("success", false);
            modelMap.put("errMsg", e.toString());
        }
        long endTime = System.currentTimeMillis();
        logger.debug("costTime:[{}ms]",endTime-startTime);
        logger.info("============end============");
        return modelMap;

    }
}
